package com.hrc.springbootdemo;

import java.util.HashMap;
import java.util.Queue;
import java.util.TreeMap;

/**
  Definition for a binary tree node.
  public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
      this.val = val;
 this.left = left;
         this.right = right;
  }
 }
 */
class Solution {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public static void main(String[] args) {
         Solution solution = new Solution();
        TreeMap<Object, Object> objectObjectTreeMap = new TreeMap<>();
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        System.out.println(solution.kthSmallest(new TreeNode(3,new TreeNode(1,null,new TreeNode(2)),new TreeNode(4)),1));
    }

    int res;
    public int kthSmallest(TreeNode root, int k) {
        dfs(root,k);
        return res;
    }
    public void dfs(TreeNode root, int k) {
        if (root == null) {
            return;
        }
        Queue queue;
        dfs(root.left,k);
        if (--k == 0) {
            res = root.val;
        }
        dfs(root.right,k);
    }

}